Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add local debug options as a dependency, but only if local_debug_options_enabled #98

Merged
merged 4 commits into from
Aug 12, 2020

Conversation

amberdixon
Copy link
Collaborator

@amberdixon amberdixon commented Aug 4, 2020

Only do this if local_debug_options_enabled is specified at command line. Make xcode specify this config.

The changes in this PR are taken from the suggested changes in https://github.com/ios-bazel-users/ios-bazel-users/blob/master/DebuggableRemoteSwift.md to get debugging working.

Note that in order for the example applications and tests in the rules_ios repo to be debuggable from Xcode, you must:

  1. Disable sandboxing in .bazelrc.
  2. Update the flag in the tools/xcodeproj_shims/build-wrapper.sh to refer to --//rules:local_debug_options_enabled rather than --@build_bazel_rules_ios//rules:local_debug_options_enabled

There are still known issues with evaluating variables from the debugger for swift tests.

rules/library.bzl Outdated Show resolved Hide resolved
xcodebuild -project Test-Target-With-Test-Host-Project.xcodeproj -quiet
# TODO: use strings to test that absolute paths and debug-prefix-map are present in the LocalDebug.swiftmodule. Not sure if this is the right palce to do it. We could also grep out the build event text file maybe.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing newline

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: spelling of place

rules/app.bzl Outdated
@@ -56,7 +56,7 @@ def ios_application(name, apple_library = apple_library, **kwargs):
"""
infoplists = write_info_plists_if_needed(name = name, plists = kwargs.pop("infoplists", []))
application_kwargs = {arg: kwargs.pop(arg) for arg in _IOS_APPLICATION_KWARGS if arg in kwargs}
library = apple_library(name = name, namespace_is_module_name = False, platforms = {"ios": application_kwargs.get("minimum_os_version")}, **kwargs)
library = apple_library(name = name, namespace_is_module_name = False, platforms = {"ios": application_kwargs.get("minimum_os_version")}, add_swift_local_debug_options = True, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should also be passed for tests as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, we could only add in the select to the deps passed to rules_apple_ios_application , and make it conditional on whether there were actually any swift files? That way, the swiftmodule that represents the app needn't be invalidated by switching the flag either

Copy link

@kastiglione kastiglione Aug 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as of Xcode 11.5, we don't need/use this workaround for apps, only tests.

…options_enabled is specified at command line. Make xcode specify this config
Copy link
Member

@segiddins segiddins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Does of of the test projects in this repo demonstrate the fix?

"-serialize-debugging-options",
],
module_name = "_LocalDebugOptions",
tags = ["no-remote"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can we also tag as manual?

xcodebuild -project Test-Target-With-Test-Host-Project.xcodeproj -quiet
# TODO: use strings to test that absolute paths and debug-prefix-map are present in the LocalDebug.swiftmodule. Not sure if this is the right palce to do it. We could also grep out the build event text file maybe.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: spelling of place

@amberdixon
Copy link
Collaborator Author

I am still seeing issues with test bundles locally. I get errors like this. This happens for tests written in swift both with and without an app host:

AppRoot-Unit-Tests: error: cannot load underlying module for 'XCTest'

Debug info from this module will be unavailable in the debugger.

warning: Swift error in scratch context: error: missing required modules:

That said, I think the changes in this PR are still correct, but perhaps we need to do a few more things in terms of setting additional lldb settings. Going to open this up for review and then continue working on these issues I'm seeing with tests locally.

@segiddins
Copy link
Member

AppRoot-Unit-Tests: error: cannot load underlying module for 'XCTest'

We might need to add in $(PLATFORM_DIR)/Developer/Library/Frameworks to FRAMEWORK_SEARCH_PATHS for test target types?

Copy link
Contributor

@gyfelton gyfelton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@@ -1,4 +1,4 @@
#!/bin/bash
set -euxo pipefail

$BAZEL_PATH build --experimental_execution_log_file=$BAZEL_BUILD_EXECUTION_LOG_FILENAME --build_event_text_file=$BAZEL_BUILD_EVENT_TEXT_FILENAME --build_event_publish_all_actions $1 2>&1 | $BAZEL_OUTPUT_PROCESSOR
$BAZEL_PATH build --experimental_execution_log_file=$BAZEL_BUILD_EXECUTION_LOG_FILENAME --build_event_text_file=$BAZEL_BUILD_EVENT_TEXT_FILENAME --build_event_publish_all_actions $1 --@build_bazel_rules_ios//rules:local_debug_options_enabled 2>&1 | $BAZEL_OUTPUT_PROCESSOR
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run the following to get test fixtures updated:

bazelisk query 'kind(xcodeproj, tests/ios/xcodeproj/...)' | xargs -n 1 bazelisk run
bazelisk query 'kind(xcodeproj, tests/macos/xcodeproj/...)' | xargs -n 1 bazelisk run
bazelisk query 'attr(executable, 1, kind(genrule, tests/macos/xcodeproj/...))' | xargs -n 1 bazelisk run
bazelisk query 'attr(executable, 1, kind(genrule, tests/ios/xcodeproj/...))' | xargs -n 1 bazelisk run
find . -type f \( -name 'WORKSPACE' -o -name '*.bzl' -o -name '*.bazel' \) | xargs buildifier -lint=fix

rules/app.bzl Outdated
@@ -61,9 +61,16 @@ def ios_application(name, apple_library = apple_library, **kwargs):
application_kwargs["launch_storyboard"] = application_kwargs.pop("launch_storyboard", library.launch_screen_storyboard_name)
application_kwargs["families"] = application_kwargs.pop("families", ["iphone", "ipad"])

local_debug_options_for_swift = []
if library.has_swift_sources:
local_debug_options_for_swift += ["@build_bazel_rules_ios//rules:_LocalDebugOptions"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we update some documentation / readme to reflect this important flag?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added comments in the BUILD.bazel where the _LocalDebugOptions target is defined. I will also reference this README: https://github.com/ios-bazel-users/ios-bazel-users/blob/master/DebuggableRemoteSwift.md

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding separate docs shouldn't be necessary, since the xcodeproj rule automatically enables the flag when necessary

@amberdixon amberdixon marked this pull request as ready for review August 11, 2020 23:18
.bazelrc Outdated
# Enable these features to test local and CI builds
# when swiftmodule caching is enabled.
build --features=swift.cacheable_swiftmodules
build --features=swift.use_global_module_cache
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: trailing newline

xcodebuild -project Test-Target-With-Test-Host-Project.xcodeproj -quiet
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: trailing newline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants